<%@ page language="java" contentType="text/html; charset=UTF-8"
         pageEncoding="UTF-8" %>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
    <title>用户信息</title>
    <style type="text/css">
        @import url(../css/form.css);

        li {
            list-style: none;
        }

        .tdOne {
            text-align: right;
        }

        #biaoGe {
            width: 80%;
            margin: 0 auto;
            margin-top: 50px;
        }

        textarea.kuang {
            height: 300px;
            width: 600px;
        }
    </style>
    <script src="${basePath}js/jquery-1.11.1.js"></script>
    <script type="text/javascript">
        //function trim(str) {
        //    var strnew = str.replace(/^\s*|\s*$/g, "");
        //    return strnew;
        //}

        $(document).ready(function () {
            $("#readerName").blur(function () {
                var readerName = $("#readerName").val();
                document.getElementById("readerNameTip").innerHTML = "<font color='#339933'>√ 用户名合格</font>";
                $.post("${basePath}reader/Reader_checkReaderName.action",
                        {readerName: readerName},
                        function (data) {
                            if (data == "success") {
                                document.getElementById("readerNameTip").innerHTML = "<font color='red'>× 该用户名已经被注册，请重新输入</font>";
                                $("#submit").attr("disabled", true);
                            }
//              for(var propName in data){
//                  $("#tip").append("<font color='red'" + propName + "--->" + data[propName] + "</font>");
//              }
                        });
            });
        });

    </script>

</head>
<body>
<h3>增加读者</h3>
<form name="readerForm" action="${basePath}reader/addReader"
      method="post">
    <input type="hidden" name="id" value="${reader.id}">
    <table id="biaoGe">
        <tr>
            <td class="tdOne">标题：</td>
            <td><input class="kuang" type="text" name="name"
                       value="${reader.name}"/></td>
        </tr>

        <tr>
            <td class="tdOne">读者电话：</td>
            <td><input class="kuang" type="text" name="phone"
                       value="${reader.phone}"/></td>
        </tr>

        <tr>
            <td class="tdOne">读者类型：</td>
            <td><select name="readerType.id">
                <option value="-1">全部</option>
                <c:forEach var="type" items="${readerTypeList}">
                    <c:choose>
                        <c:when test="${type.id == reader.readerType.id }">
                            <option value="${type.id}" selected="selected">${type.name}</option>
                        </c:when>
                        <c:otherwise>
                            <option value="${type.id}">${type.name }</option>
                        </c:otherwise>
                    </c:choose>
                </c:forEach>
            </select></td>
        </tr>
        <tr>
            <td colspan="2" align="center">
                <input class="btn" type="submit" value="保存读者" name="commit" />
            </td>
        </tr>
    </table>
</form>
<span id="tip"></span>
</body>
</html>
